#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"
#include "../../../../core/shader_color.h"
#include "../../../../core/shader_std.h"


layout(push_constant, scalar) uniform DRAWPROP_push_constants {
	S_ConstPush_TickMark const_push;
};

layout(std140, set = 0, scalar, column_major, binding = DEF_BINDING_PROJECT) uniform U_Matrix0 {
	mat4 mat_ProjecView[2];
};

layout(std430, set = 1, binding = 1, scalar, column_major) readonly buffer U_Matrix1 {
	mat3 tranformG[];
};
layout(std430, set = 1, binding = 2, scalar, column_major) readonly buffer U_Matrix2 {
	mat3 tranformL[];
};

layout(std430, set = 2, binding = 1, scalar) readonly buffer U_Matrix3 {
	uvec2 elementColor[];
};



layout(location = 0) out VS_GS_VERTEX {
	vec4 vVertB;
	vec4 vVertE;
	vec4 vColor;
}vertex_out;


void main(void){
	mat3 matG = tranformG[const_push.m_Offset_TranformG];
	mat3 matL = tranformL[const_push.m_Offset_TranformL + gl_DrawID];
	uvec2 shaderPack = elementColor[const_push.m_Offset_Color + gl_DrawID];

	//vertex_out.vColor = f_glsl_buildColor(elementColor[const_push.m_Offset_Color + gl_DrawID]);
	vertex_out.vColor = f_glsl_buildColor(shaderPack.x);
	
	float gap = const_push.ox * float(gl_VertexIndex);
	
	vec3 vert = vec3(0,0,1);
	const_push.m_Dir == DEF_TickMark_H ? vert.y = gap : vert.x = gap;
	vert = matL * vert;
	
	
	vec4 v = vec4(matG * vert, 1.0);
	vertex_out.vVertB = mat_ProjecView[0] * v;
	
	const_push.m_Dir == DEF_TickMark_H ? vert.x += const_push.w : vert.y += const_push.h;
	
	
	v = vec4(matG * vert, 1.0);
	vertex_out.vVertE = mat_ProjecView[0] * v;

	if ( bool(gl_VertexIndex&1) == true ) {
		vertex_out.vColor.a *= 0.5;
	} else {
		vertex_out.vColor.rgb *= 0.5;
	}
	//vertex_out.vVertB = mat_ProjecView * vec4(vec3(10,10,0) * matL * matG, 1);
	//vertex_out.vVertE = mat_ProjecView * vec4(vec3(2000,2000,0) * matL * matG, 1);
}



